# ----------------------------------------------------------------------------
# Copyright (c) Atg Robotics
# Author: Haotian Yu (haotianyuu@163.com)
# Data: 2022/03/10
# ----------------------------------------------------------------------------
print("------------补齐打印------------")
[print("{:03}".format(i+1)) for i in range(3)]

### 排序
print("------------sorted函数------------")
L = [("a", 1), ("b", -1), ("b", 0)]
print(list(sorted(L, key=lambda x: x[1])))

D = {"a": 1, "c": -1, "b": 0}
print(sorted(D.items(), key=lambda x: x[0]))

D = {"a": 1, "C": -1, "b": 0}
print(sorted(D.items(), key=lambda x: x[0].lower()))

### 列表
# filter函数
print("------------filter函数------------")
a = [1, 2, 3, 4, 5, 6]
sA = list(filter(lambda x: x % 2 == 0, a))
print(sA)

print("------------count函数------------")
a += [2, 3, 4]
print(a)
print(a.count(3))

print("------------index函数------------")
print(a.index(2, 3, -1))

print("------------pop函数------------")
a = list(set(a))
print(a)
# pop递归, a清空了
def traverse(L):
    if len(L) <= 0: return
    print(L.pop(0))
    traverse(L)
traverse(a)


print("------------map函数------------")
# map函数: 将列表每个元素执行相同的操作
mA = list(map(lambda x: x**2, a))
# 也可以这样
mA = [e**2 for e in a]

# map实现两个列表逐个元素相加
b = [2, 3, 4, 5, 6, 7]
mC = list(map(lambda x, y: x+y, a, b))
print(mC)

